package com.sline.test;

import java.util.ArrayList;

public class GetLuckyNumber {
    public static void main(String[] args) {

        System.out.println(getLuckyNumber(8));
    }

    static public int getLuckyNumber(int number) {

        ArrayList<Integer> numberList = new ArrayList<>();
        for (int i = 0; i < number; i++) {
            numberList.add(i);
        }

        int count = 0;
        for (int i = 0; numberList.size() != 1; i++) {
            if (i == numberList.size()) {
                i = 0;
            }

            if (count % 3 == 0) {
                numberList.remove(i);
            }

            i--;

            count ++;
        }

        return numberList.get(0);
    }
}
